package patrol.mobile.com.mobilepatrol.activity.toll;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.Call;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.BaseActivity;
import patrol.mobile.com.mobilepatrol.api.Urls;
import patrol.mobile.com.mobilepatrol.bean.JobEvaluationInformationBean;
import patrol.mobile.com.mobilepatrol.utils.CommonUtil;
import patrol.mobile.com.mobilepatrol.utils.GsonUtil;
import patrol.mobile.com.mobilepatrol.utils.TimeUtils;
import patrol.mobile.com.mobilepatrol.utils.net.HttpCallBack;
import patrol.mobile.com.mobilepatrol.utils.net.HttpSender;

public class MyEvaluationDetailActivity extends BaseActivity {

    @BindView(R.id.tv_bei_kaohe)
    TextView tvBeiKaohe;
    @BindView(R.id.tv_kaohe)
    TextView tvKaohe;
    @BindView(R.id.tv_kaohe_score)
    TextView tvKaoheScore;
    @BindView(R.id.tv_koufen)
    TextView tvKoufen;
    @BindView(R.id.tv_koufen_biaozhun)
    TextView tvKoufenBiaozhun;
    @BindView(R.id.btn_agree)
    Button btnAgree;
    @BindView(R.id.btn_appeal)
    Button btnAppeal;
    private int position;
    private String id;
    private String assessmentPost;
    private JobEvaluationInformationBean bean;
    private String deviceDetailImgBeans;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_my_evaluation_detail;
    }

    @Override
    public void initView() {
        super.initView();
        iv_back.setImageResource(R.mipmap.up_white);
        iv_back.setVisibility(View.VISIBLE);
        iv_back.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        CommonUtil.exitActivityAndBackAnim(MyEvaluationDetailActivity.this, true);
                    }
                });
        tv_center_title.setVisibility(View.VISIBLE);
        tv_center_title.setText("考核明细");
    }

    @Override
    public void initData() {
        super.initData();
        id = getIntent().getStringExtra("id");
        assessmentPost = getIntent().getStringExtra("assessmentPost");
        position = getIntent().getIntExtra("position", 0);
        requestData(id);
    }

    private void requestData(String id) {
        HttpSender sender = new HttpSender(this, baseUrl, Urls.GETMYORGPOSTENTITY);
        HashMap<String, String> map = new HashMap<>();
        map.put("id", id);
        sender.requestPost(map, new HttpCallBack(sender) {
            @Override
            public void onError(String code, Call call, Exception e) {

            }

            @Override
            public void onResponse(String code, String response) {
                Log.e("我的实体", response);
                bean = GsonUtil.GsonToBean(response, JobEvaluationInformationBean.class);
                tvBeiKaohe.setText(bean.getCheckName());
                tvKaohe.setText(bean.getAssessor());
                tvKaoheScore.setText(bean.getDeductScore() + "分");
                tvKoufen.setText(TimeUtils.timeString(System.currentTimeMillis()));
                tvKoufenBiaozhun.setText(bean.getReason());
            }
        });
    }

    @Override
    public void setListener() {

    }

    @OnClick({R.id.btn_agree, R.id.btn_appeal})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_agree:
                sure();
                break;
            case R.id.btn_appeal:
                Intent intent = new Intent(MyEvaluationDetailActivity.this, AppealActivity.class);
                intent.putExtra("data", bean);
                intent.putExtra("id", id);
                intent.putExtra("assessmentPost", assessmentPost);
                intent.putExtra("attachList", deviceDetailImgBeans);
                startActivity(intent);
                break;
        }
    }

    private void sure() {
        HttpSender sender = new HttpSender(this, baseUrl, Urls.getMyOrgPostMakeSure);
        HashMap<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put("auditName", "已确认");
        map.put("auditFlag", "2");
        sender.requestPost(map, new HttpCallBack(sender) {
            @Override
            public void onError(String code, Call call, Exception e) {
                showToast("确认失败");
            }

            @Override
            public void onResponse(String code, String response) {
                showToast("确认成功");
                finish();
            }
        });
    }
}
